package com.lagou.edu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.lagou.edu.dao.OrderMapper;
import com.lagou.edu.pojo.Order;
import com.lagou.edu.service.OrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService{

	@Resource
	OrderMapper orderMapper;

	@Override
	public void addOrder(Order order) {
		orderMapper.insert(order);
	}

	@Override
	public Order selectOrderByOrderId(String orderId) {
		System.out.println(orderId);
		Order orderInfo1 = new Order();
		orderInfo1.setOrderId(orderId);
		orderInfo1 = orderMapper.selectOne(new QueryWrapper<Order>().eq("order_id",orderId));
		System.out.println(orderInfo1);
		return orderInfo1;
	}

	@Override
	public void updateOrder(String orderId, Integer state) {
		UpdateWrapper<Order> updateWrapper = new UpdateWrapper<>();
		updateWrapper.eq("order_id",orderId).set("state", state);
		orderMapper.update(null, updateWrapper);
	}

	@Override
	public List<Order> selectOrderList(Integer state) {
		Order order = new Order();
		order.setState(state);
		return orderMapper.selectList(new QueryWrapper<Order>()
				.eq("state", state));

	}
}
